package com.laboratory.report.lab02.lab0201;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 运动项目
 */
@Data
public class Event {

    /**
     * 项目名称
     **/
    private String name;
    /**
     * 项目场地
     **/
    private String place;
    /**
     * 项目允许参与的人数
     **/
    private int persons;

    private List<Athlete> athletes = new ArrayList<>();

    public Event(String name, String place, int persons) {
        this.name = name;
        this.place = place;
        this.persons = persons;
    }

    public void joinEvent(Athlete athlete) {
        if (athletes.size() >= persons) {
            System.out.println(name + "人数已满," + athlete.getName() + "无法参赛");
            return;
        }
        athletes.add(athlete);
        System.out.println("参与" + name + "项目的人有:" + athletes.stream().map(a->a.getName()).collect(Collectors.toList()));
    }
}
